package com.shujia.scala

object Demo25Cast {
  def main(args: Array[String]): Unit = {
    val list: List[Int] = List(1, 2, 3, 4, 5, 6, 1, 1, 2, 23, 1, 1, 1)

    //去重
    println(list.distinct)

    //转换成set实现去重
    val set: Set[Int] = list.toSet
    println(set)

    //set转换成list才可以排序
    val list1: List[Int] = set.toList
    println(list1)
    println(list1.sortBy(i => i))


    val users: Map[String, String] = Map("001" -> "张三", "002" -> "李四", "003" -> "王五")
    //字典转换列表
    val userList: List[(String, String)] = users.toList
    println(userList)


    val ages: List[(String, Int)] = List(("001", 21), ("002", 22), ("003", 23))
    //列表转换成字典，列表中的元素类型只能是二元组
    val ageMap: Map[String, Int] = ages.toMap
    println(ageMap)

  }
}
